#!/bin/csh -f
# updateLink runs as a cronjob from /etc/cron.d/atnf-web on Sunday morning 1am
# It updates the index links for CA and Mopra schedules so it starts up on
# the current page.
# The file "nextweek" is used to skip every other week, if it exists we remove
# it and come back next week for an index update, otherwise we do it now.
#
# skip every other week
cd current
if (-f nextweek) then
  rm -f nextweek
  exit
endif
touch nextweek
# update current index file for CA
set current = `/bin/ls -l CAindex.html | sed -e 's/.*> //'`
set num = `echo $current | sed -e 's/CA0//' -e 's/.html//'`
set next = `expr 1 + $num`
if ($next < 10) set next = "0$next"
set nextfile = `echo $current | sed -e "s/$num/$next/"`
if (-f $nextfile) then
  rm -f CAindex.html
  ln -s $nextfile CAindex.html
endif

#update current index file for MP
set current = `/bin/ls -l MPindex.html | sed -e 's/.*> //'`
set num = `echo $current | sed -e 's/MP0//' -e 's/.html//'`
set next = `expr 1 + $num`
if ($next < 10) set next = "0$next"
set nextfile = `echo $current | sed -e "s/$num/$next/"`
if (-f $nextfile) then
  rm -f MPindex.html
  ln -s $nextfile MPindex.html
endif

